package com.shxzz.easy12306.services.user.controller;

import com.shxzz.easy12306.framework.starter.convention.result.Result;
import com.shxzz.easy12306.framework.starter.convention.result.Results;
import com.shxzz.easy12306.services.user.dto.req.UserDeletionReqDTO;
import com.shxzz.easy12306.services.user.dto.req.UserUpdateReqDTO;
import com.shxzz.easy12306.framework.starter.common.dto.user.UserQueryActualRespDTO;
import com.shxzz.easy12306.services.user.dto.resp.UserQueryRespDTO;
import com.shxzz.easy12306.services.user.service.UserService;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理控制层
 * @author shxzz
 * @create 2024-02-29-21:49
 */
@RequiredArgsConstructor
@RestController
public class UserController {

    private final UserService userService;

    /**
     * 根据用户名查询用户信息
     */
    @GetMapping("/api/user-service/query")
    public Result<UserQueryRespDTO> queryUserByUsername(@RequestParam("username") @NotBlank String username) {
        return Results.success(userService.queryUserByUsername(username));
    }

    /**
     * 根据用户名查询用户真实信息
     */
    @GetMapping("/api/user-service/actual/query")
    public Result<UserQueryActualRespDTO> queryActualUserByUsername(@RequestParam("username") @NotBlank String username) {
        return Results.success(userService.queryActualUserByUsername(username));
    }

    /**
     * 修改用户信息
     */
    @PostMapping("/api/user-service/update")
    public Result<Void> update(@RequestBody UserUpdateReqDTO requestParam) {
        userService.update(requestParam);
        return Results.success();
    }

    /**
     * 注销用户
     */
    @PostMapping("/api/user-service/deletion")
    public Result<Void> deletion(@RequestBody UserDeletionReqDTO requestParam) {
        userService.deletion(requestParam);
        return Results.success();
    }

}
